#ifndef _FIXED_SIZE_ALLOCATOR_HPP_
#define _FIXED_SIZE_ALLOCATOR_HPP_

#include "base.hpp"

class FixedSizeAllocator
{
public :
	FixedSizeAllocator(int block_size, int block_num);
	~FixedSizeAllocator();

	void *allocate();
	void deallocate(void * addr);

	int block_size() const { return _block_size; }

	bool empty() const { return (-1 == _head); }
	int free_count() const { return _free_count; }

	void display();

private :
	void * get_addr_by_index(int index);
	int get_index_by_addr(void * addr);

private :
	int _head;
	int _free_count;

	const int _block_size;
	const int _block_num;

	char * _base;
	char * _end;
};

#endif

